<?php
class navigation_system
{
	var $_navigation = array();
	var $_config;

	private static $instance = null;

	protected function __construct()
	{
		//Konfiguration initialisieren
		$this->_config = config_system::getInstance();
	}

	private function __clone(){}

	public static function getInstance()
	{
		if(self::$instance == null)
		{
			self::$instance = new navigation_system();
		}
		return self::$instance;
	}

	public function getNavElement($key)
	{
		if(!isset($this->_navigation[$key]))
		{
			return false;
		}

		return $this->_navigation[$key];
	}

	public function createNavElement($key,$nav = array())
	{
		$html = "\t\t<nav>\n";
		$html .= "\t\t\t<ul>\n";
		foreach($nav as $value)
		{
			if(is_string($value))
			{
				$html .= "\t\t\t\t<li><a href=\"/".$value."\">".$value."</a></li>\n";
				
				if($this->_config->getConfig('navigation module',$value))
				{
					$subnav = $this->_config->convertConfig('navigation module',$value);
					foreach($subnav as $link)
					{
						$html .= "\t\t\t\t<li class=\"sub\">- <a href=\"/".$link['href']."\">".$link['name']."</a></li>\n";	
					}
				}
			}
			if(is_array($value))
			{
				$html .= "\t\t\t\t<li><a href=\"/".$value['href']."\">".$value['name']."</a></li>\n";				
			}
		}
		$html .= "\t\t\t</ul>\n";
		$html .= "\t\t</nav>";

		$this->_navigation[$key] = $html;
	}
}
